#pragma once

#include "Ray.h"
#include "float.h"
#ifndef M_PI
#define M_PI       3.14159265358979323846   // pi
#endif // !1
class Camera {
public:
	Camera() {
		lower_left_corner = Vector3(-2.0, -1.0, -1.0);
		horizontal = Vector3(4, 0, 0);
		vertical = Vector3(0.0, 2.0, 0.0);
		origin = Vector3(0, 0, 0);
	}
	Camera(float vfov, float aspect) {
		origin = Vector3(0, 0, 0);
		float theta = vfov * M_PI / 180;
		float half_height = tan(theta / 2);
		float half_width = aspect * half_height;
		lower_left_corner = origin - Vector3(0, half_height, 0) - Vector3(half_width, 0, 0) - Vector3(0, 0, 1);
		horizontal = 2 * Vector3(half_width, 0, 0);
		vertical = 2 * Vector3(0, half_height, 0);
	}

	Camera(Vector3 lookfrom, Vector3 lookAt, Vector3 vUp, float vFov, float aspect) {
		Vector3 u, v, w;
		float theta = vFov * M_PI / 180;
		float half_height = tan(theta / 2);
		float half_width = aspect * half_height;
		


		origin = lookfrom;
		w = unit_vector(lookfrom - lookAt);
		u = unit_vector(cross(vUp, w));
		v = cross(w, u);
		lower_left_corner = origin -half_width * u - half_height * v - w;
		horizontal = 2 * half_width*u;
		vertical = 2 * half_height * v;
	}

	Ray get_ray(float u, float v) {
		return Ray(origin, lower_left_corner + u * horizontal + v * vertical);
	}

	Vector3 lower_left_corner;
	Vector3 horizontal;
	Vector3 vertical;
	Vector3 origin;
};